package edu.sysu.cshare.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Scrollbar;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneLayout;

import edu.sysu.cshare.control.UserManager;
import edu.sysu.cshare.model.Clazz;
import edu.sysu.cshare.model.User;
import edu.sysu.cshare.util.gui.GUI;

class SharingMouseListener implements MouseListener{
		User user;
		public SharingMouseListener(User u){
			user=u;
		}
		public void mouseClicked(MouseEvent ev) {
			try{
				String url =user.getLastIP();
				Runtime.getRuntime().exec("explorer \\\\"+url+"\\");
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		public void mouseEntered(MouseEvent e) {}
		public void mouseExited(MouseEvent e) {}
		public void mousePressed(MouseEvent e) {}
		public void mouseReleased(MouseEvent e) {}
}


public class Pnl_Sharing extends JPanel {

	/**
	 * Create the panel.
	 */
	JPanel p;
	UserManager user_mgr;
	
	public Pnl_Sharing(UserManager u) {
		user_mgr=u;
		setLayout(new BorderLayout(0, 0));
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);

		this.p=new JPanel();
		GridLayout g =new GridLayout(0,5);
		p.setLayout(new GridLayout(0,5));
		JScrollPane sp =new JScrollPane(p);
		User user=user_mgr.getActor();
		List<User> mates=user.getClazz().getStudents();
		
		for (int i = 0; i < mates.size(); i++) {
			JButton l =new JButton();
			User us=mates.get(i);
			l.setText(us.getName());
			l.setFont(new Font("宋体", Font.ITALIC, 20));
			l.addMouseListener(new SharingMouseListener(us) );
			p.add(l);
		}
		//p.add(new Scrollbar());
		//p.setSize(3200, 10000);
		
		tabbedPane.addTab("hello world", null, sp, null);
		add(tabbedPane, BorderLayout.CENTER);

	}

}
